﻿#if NET451
using System;
using System.Configuration;

namespace RabbitMQExtension
{
    public partial class MQHelper : IDisposable
    {
        /// <summary>
        /// 无参构造函数，从配置文件，按照约定读取数据
        /// 从appsettings MQ 节点中读取 配置节点
        /// Host,UserName,Password
        /// </summary>
        public MQHelper()
        {
            var host = ConfigurationManager.AppSettings["MQ.Host"];
            var userName = ConfigurationManager.AppSettings["MQ.UserName"];
            var password = ConfigurationManager.AppSettings["MQ.Password"];
            var virtualHost = ConfigurationManager.AppSettings["MQ.VirtualHost"];

            var config = new MQConfig(host, userName, password, virtualHost);

            if (string.IsNullOrEmpty(config.Host))
                throw new ArgumentNullException(nameof(config.Host));
            if (string.IsNullOrEmpty(config.UserName))
                throw new ArgumentNullException(nameof(config.UserName));
            if (string.IsNullOrEmpty(config.Password))
                throw new ArgumentNullException(nameof(config.Password));
            Open(config);
        }
    }
}
#endif